#include "time.h"
#include "stdlib.h"
#include "stdio.h"

int main()
{
    int stime,a,z,t,i,c,m,g,s,j,k,l[4];
    long ltime;
    ltime = time(NULL);
    stime = (unsigned int)ltime/2;
    srand(stime);
    z = random()%9999;
    printf("I have a number with 4 digits in mind, please guess.\n");
    for(c = 1;;c++)
    {
        printf("Enter a number with 4 digits:");
        scanf("%d",&g);
        a = z;
        j = 0;
        k = 0;
        l[0] = l[1] = l[2] = l[3] = 0;
        for(i = 1;i<5;i++)
        {
            s = g;
            m = 1;
            for(t = 1;t<5;t++)
            {
                if(a%10 == s%10)
                {
                    if(m&&t != l[0]&&t != l[1]&&t != l[2]&&t != l[3])
                    {
                        j++;
                        m = 0;
                        l[j-1] = t;
                    }
                    if(i == t)
                    k++;
                }
                s /= 10;
            }
            a /= 10;
        }
        printf("You have correctly guessd %d digits,\n",j);
        printf("and correctly guessed %d digits in exact position.\n",k);
        if(k == 4)
        break;
    }
    printf("Now you have correctly guessed the whole number after %d times.\n",c);
}